const globalIp = getApp().globalData.userIp
const nowTime = getApp().globalData.nowTime
Page({
  /**
   * 页面的初始数据
   */
  data: {
    searchResult:false,
    dataColor: false,
    dataTime:"日期选择",
    dataTime1:"日期选择",
    dataFlag: false, //控制综合下拉框是否显示
    isShowAll:false,
    nowTime: nowTime,
    projectList:[],
    openId:''
  },

  dataShow: function () {//日期下拉
    if (this.data.dataFlag){
      this.setData({
        dataFlag : !this.data.dataFlag
      })
    }else{
      this.setData({
        dataFlag: !this.data.dataFlag
      })
    }
  },

  changeDate1(e) {
    this.setData({
      dataTime1: e.detail.value,
      dataTime: e.detail.value,
      dataFlag: false,
      dataColor: true
    })
    this.getProject()
  },

   // 统一请求
   getProject(e) {
    let that = this;
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    wx.request({
      url: globalIp + 'home/ordr/showGoalReachForMonthPeo',
      data: {
        sdate: that.data.dataTime1 == '日期选择' ? nowTime.substring(0,7) : that.data.dataTime1,
        openId: that.data.openId || wx.getStorageSync('userInfo').openid
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        if (res.data.jsonObject) {
          var data = res.data.jsonObject.data;
          var arr = [];
          var res = [];
          for (var i in data) {
            arr[i] = [];
            for(var j in data[i]) {
              arr[i].push(data[i][j]);
            }
          }
          for (var i = 0; i < arr[0].length; ++i) {
            res[i] = [];
            for (var j = 0; j < arr.length; ++j) {
              res[i][j] = arr[j][i];
            }
          }
          that.setData({
            projectList: res
          })
        } 
      },
      fail: function(res) {
        wx.showToast({
          title: '请返回上一页面，重新请求',
          icon: 'none',
          duration: 2000,
        })
      },
      complete: function(res) {
        wx.hideLoading()
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getProject();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  }

})